<?php
    if($annonce_details->num_rows() > 0):
        $annonce_detail = $annonce_details->row();
        $id = $annonce_detail->id;
        $description = $annonce_detail->description;
        $title = $annonce_detail->title;
        $content = $annonce_detail->content;
        $sub_region_id = $annonce_detail->sub_region_id;
        $sub_region_name = $annonce_detail->sub_region_name;
        $image_path = "./assets/annonce/". $annonce_detail->images;
        $posted_date = $annonce_detail->date_posted;    
        $expired_date = $annonce_detail->date_expried;   
        if(file_exists($image_path)&&$annonce_detail->images!=NULL){
            $image_path = base_url() . "assets/annonce/". $annonce_detail->images;    
        }else{
            $image_path = base_url() . "images/noimage.gif"; 
        }
    $dropdown_data= array(
    'table_name'=>'animus_sub_region',
    'key_field'=>'id',
    'value_field'=>'name'
    );
    $level_dropdown_data = array(
    'table_name'=>'animus_anounce_level',
    'key_field'=>'id',
    'value_field'=>'name'
    );
    $selected_level = isset($annonce_detail->level)?$annonce_detail->level:0;
    $months = array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
    "Oct", "Nov", "Dec");
    ini_set("date.timezone", "Europe/Paris");
    $this_day = now();
    $pattern_year = "%Y";
    $str_year = mdate($pattern_year, $this_day);

    for ($i = 0; $i < 12; $i++) {
        $month_data[$i + 1] = $months[$i];
    }
    for ($i = 0; $i < 31; $i++) {
        $day_data[$i + 1] = $i + 1;
    }
    for ($i = $str_year; $i > 1900; $i--) {
        $year_data[$i] = $i;
    }
    $pattern = "%Y-%m-%d";
    $str_date_expired = isset($expired_date)? mdate($pattern, $expired_date):mdate($pattern,time());
?>


<div id="wrapper-content">
    <table class="titrepage" width="100%">
        <tr>
            <td >Modifier Annonce</td>
            <td align="right"> </td>
        </tr>
    </table>
    <?php if($this->session->flashdata('success')):?>
        <p style="background:lime; color: blue;"><?php echo $this->session->flashdata('success')?></p>
    <?php endif;?>
    <form method="post" enctype="multipart/form-data" action="<?php echo current_url();?>">
        <table width="100%" class="list">
            <tr>
                <td>Publié par :<?php echo $annonce_detail->username?></td>
            </tr>
            <tr>
                <td>
                    <label>Type d'anonce :</label><br/>
                    <label><?php echo form_dropdown('level', dropdown_data($level_dropdown_data),$selected_level);?></label> 
                </td>
            </tr>
            <tr>
                <td>
                    <label >Image :</label>    
                    <p><img src="<?php echo $image_path; ?>" width="90px"/><input type="file" name="userfile" id="userfile" size="25"/></p>
                </td>
            </tr>
            <tr>
                <td>
                    <label>Titre :</label>
                     <p><textarea rows="2" cols="80" name="title" size="30" ><?php echo $title ?></textarea></p>
                     <?php if(form_error('title')):?>
                        <?php echo form_error('title'); ?>
                    <?php endif;?>
                </td>
            </tr>

            <tr>
                <td>
                    <label>Description:</label>
                    <p><textarea rows="4" cols="80" name="description" size="30" ><?php echo $description ?></textarea></p>
                </td>
            </tr>
            <tr>
                <td>
                    <label>Contenu :</label>
                    <?php
                        $data = array(
                        'name' => 'content',
                        'id' => 'content',
                        'width' => '692',
                        'height' => '280',
                        'value' =>$content
                        );
                    ?>
                    <p><?php echo form_fckeditor($data);?></p>
                    <?php if(form_error('content')):?>
                        <?php echo form_error('content'); ?>
                    <?php endif;?>
                </td>
            </tr>

            <tr>
                <td>
                    <label>Sub-region :</label>
                    <p><?php echo form_dropdown('sub_reg', dropdown_data($dropdown_data), $sub_region_id);?></p>
                </td>
            </tr>    

            <tr>
                <td>
                    <label>Expiré :</label>
                    <p>J :<?php echo form_dropdown('expired_date', $day_data, get_date_part($str_date_expired,'day'), 'id="day"'); ?>
                    M :<?php echo form_dropdown('expired_month', $month_data, get_date_part($str_date_expired,'month'), 'id="month"'); ?> 
                    A :<?php echo form_dropdown('expired_year', $year_data, get_date_part($str_date_expired,'year'), 'id="year"'); ?></p>
                </td>
            </tr>

            <tr>
                <td> <input type="submit" value=" Enregistrer " name="modifier" id="btnchange"/> </td>
            </tr>
        </table>
    </form>
<?php endif;?>
</div>
